package org.hw.proxy.dynamic;

import org.hw.proxy.Animal;
import org.hw.proxy.Dog;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class DynamicProxy {
    public static void main(String[] args) throws IllegalAccessException, InstantiationException {
        MyInvocationHandler handler=new MyInvocationHandler(new Dog());

        Animal dogProxy= (Animal) Proxy.newProxyInstance(Animal.class.getClassLoader(),new Class<?>[]{Animal.class},handler);
        dogProxy.eating("apple");

        Class<?> dogclass=Proxy.getProxyClass(Dog.class.getClassLoader(),new Class<?>[]{Animal.class});
        System.out.println(dogclass.getName());
        for (Method m:dogclass.getDeclaredMethods()){
            System.out.println(m.getName());
        }

    }


}
